package com.gaussian.property.app.controller;

import com.gaussian.property.app.service.TagService;
import com.gaussian.property.app.vo.AddTag;
import com.gaussian.property.module.biz.entity.AppUser;
import com.songqi.common.core.domain.OptionVo;
import com.songqi.common.core.domain.R;
import com.songqi.common.web.request.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @author: songqi(13776346982)
 * @date: 2024/4/9 23:32
 */
@Api(tags = "用户标签相关操作")
@Validated
@RestController
@RequestMapping("tag/")
public class TagController extends BaseController {


    @Resource
    private TagService tagService;;

    @ApiOperation("查询我的标签列表")
    @GetMapping("queryMyTagList")
    public R<List<OptionVo>> queryMyTagList(){
        AppUser appUser = (AppUser) getTokenUser();
        List<OptionVo> optionVoList = tagService.queryUserTagList(appUser.getAppUserId());
        return R.success(optionVoList);
    }

    @ApiOperation("添加标签。返回标签选项")
    @PostMapping("addTag")
    public R<OptionVo> addTag(@RequestBody @Validated AddTag addTag){
        AppUser appUser = (AppUser) getTokenUser();
        return R.success(tagService.addTag(appUser.getAppUserId(), addTag.getTagName()));
    }

    @ApiOperation("删除标签")
    @PostMapping("deleteTag/{tagId}")
    public R<Void> deleteTag(@ApiParam("标签id。取标签列表中的value字段") @PathVariable String tagId){
        tagService.delTag(tagId);
        return R.success();
    }
}



